﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Data.Entity;
using System.Net.Security;
using System.Security.Policy;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Exchange.WebServices.Data;

namespace EKAABSInformationManagement.Service
{
    public class mailService
    {
        public static void sendMail(string userName, string pwd, string uri, string subject, string body, IEnumerable<string> recipients, IEnumerable<string> ccs)
        {
            try
            {
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new WebCredentials(userName, pwd);
                service.Url = new Uri(uri);
                EmailMessage message = new EmailMessage(service);
                message.Subject = subject;
                message.Body = new MessageBody();
                message.Body.BodyType = BodyType.Text;
                message.Body.Text = body;
                if (recipients != null && recipients.Count() > 0) message.ToRecipients.AddRange(recipients);
                if (ccs != null && ccs.Count() > 0) message.CcRecipients.AddRange(ccs);
                message.SendAndSaveCopy();
            }
            catch { }
        }
        public static void sendMail(string userName, string pwd, string uri, string subject, string body, string recipient, string cc)
        {
            try
            {
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                service.Credentials = new WebCredentials(userName, pwd);
                service.Url = new Uri(uri);
                EmailMessage message = new EmailMessage(service);
                message.Subject = subject;
                message.Body = new MessageBody();
                message.Body.BodyType = BodyType.Text;
                message.Body.Text = body;
                message.ToRecipients.Add(recipient);
                if (!string.IsNullOrEmpty(cc)) message.CcRecipients.Add(cc);
                message.SendAndSaveCopy();
            }
            catch { }
        }
    }
}
